package webbrow.member.model;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mybatis.spring.SqlSessionTemplate;

public class MemberDaoImpl implements MemberDao {
	private SqlSessionTemplate sqlsessionTemplate;
	@Override
	public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
		this.sqlsessionTemplate = sqlSessionTemplate;
	}
	@Override
	public int selectCountById(String id){
		return this.sqlsessionTemplate.selectOne("member.isExistId", id);
	}
	@Override
	public int selectCountByEmail(MemberVO mvo) {
		// TODO Auto-generated method stub
		return this.sqlsessionTemplate.selectOne("member.isExistEmail",mvo);
	}
	@Override
	public int selectCountByEmailReg(String email) {
		
		return this.sqlsessionTemplate.selectOne("member.isExistEmailReg",email);
	}
	@Override
	public void insertMember(MemberVO mvo)throws SQLException {
		System.out.println("test");
		sqlsessionTemplate.insert("member.insertMember",mvo);
		
	}
	@Override
	public MemberVO selectMemberByLogin(MemberVO mvo) throws SQLException{
		return sqlsessionTemplate.selectOne("member.selectMemberByLogin",mvo);
	}
	@Override
	public MemberVO selectMemberByUpdate(MemberVO vo) {
		
		return sqlsessionTemplate.selectOne("member.selectMemberByUpdate",vo);
	}
	@Override
	public MemberVO selectMyInfo(String id) throws SQLException{
		// TODO Auto-generated method stub
		return sqlsessionTemplate.selectOne("member.selectMyInfo",id);
	}
	@Override
	public MemberVO selectMemberInfo(MemberVO vo) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void updateMember(MemberVO mvo) {
		// TODO Auto-generated method stub
		sqlsessionTemplate.update("member.updateMember",mvo);
	}
	@Override
	public int updateDropout(String id) throws SQLException{
		// TODO Auto-generated method stub
		return sqlsessionTemplate.delete("member.secessionMember",id);
	}
	/**
	 * 관리자 페이지 - 전체 회원 리스트 보기
	 */
	@Override
	public List<MemberVO> selectMemberAll() throws SQLException {
		return sqlsessionTemplate.selectList("member.selectMemberAll");
	}
	@Override
	public String selectPasswordByUserInfo(HashMap map) throws SQLException {
		System.out.println(map);
		return sqlsessionTemplate.selectOne("member.checkPassword",map);
	}
	
	/**
	 * 탈퇴 유무를 확인하는 메소드
	 */
	@Override
	public int selectDropout(String id) throws SQLException {
		return this.sqlsessionTemplate.selectOne("member.selectDropout", id);
	}
	
}
